﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using GameSchoolApplication.Models;
using GameSchoolApplication.Repository;

namespace GameSchoolApplication.Controllers
{
	[Authorize]
    public class QuestionController : Controller
    {
        private TaskRepository _task = new TaskRepository();
       
		/// <summary>
		/// Creates a new question that belongs to a spedified test
		/// </summary>
		/// <param name="testId"></param>
		/// <returns></returns>
        [HttpGet]
        public ActionResult Create(int testId)
        {
            Test test = _task.GetTestById(testId);
            return View(new Question { Test = test, TestId = testId });
        }

		/// <summary>
		///	Posts back a question that has been created
		/// </summary>
		/// <param name="question"></param>
		/// <returns></returns>
        [HttpPost]
        public ActionResult Create(Question question)
        {
            if (ModelState.IsValid)
            {
                _task.AddQuestion(question);
                return RedirectToAction("Details", "Test", new { id = question.TestId });
            }
            return View(question);
        }
		
		/// <summary>
		/// Gets a specified question by id 
		/// </summary>
		/// <param name="id"></param>
		/// <returns></returns>
		[HttpGet]
        public ActionResult Details(int id)
        {
            Question question = _task.GetQuestion(id);
            return View(question);
        }

    }
}
